package org.example.springboot137.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.springboot137.entity.Auction;
import org.example.springboot137.entity.PageBase;
import org.example.springboot137.mapper.AuctionMapper;
import org.example.springboot137.service.AuctionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class AuctionServiceImpl extends ServiceImpl<AuctionMapper, Auction> implements AuctionService {
    @Autowired
    private AuctionMapper auctionMapper;

    @Override
    public Object auctionList(int pageNo, int pageSize,String auctionName) {
        QueryWrapper<Auction> wrapper=new QueryWrapper<>();
        wrapper.like("auctionName",auctionName!=null?auctionName:"").or().like("auctionDesc",auctionName!=null?auctionName:"");

        wrapper.orderByDesc("auctionId");
        IPage<Auction> aIpage=new Page<>(pageNo,pageSize);
        //调用方法
        IPage<Auction> page=this.page(aIpage,wrapper);
        /*ResponseEntity responseEntity=new ResponseEntity();
        responseEntity.setData(page.getRecords());
        responseEntity.setCount(page.getTotal());*/
        PageBase pageBase=new PageBase();
        pageBase.setPageCode(pageNo);
        pageBase.setPageSize(pageSize);
        pageBase.setList(page.getRecords());
        pageBase.setTotalCount((int)page.getTotal());
        return pageBase;
    }

    @Override
    public String updateAuction(Auction auction) {
        return auctionMapper.updateAuction(auction)>0?"修改成功！":"修改失败";
    }

    @Override
    public Object deleteA(int id) {
        QueryWrapper<Auction> wrapper=new QueryWrapper<>();
        wrapper.eq("auctionId",id);
        return auctionMapper.delete(wrapper);
    }

    @Override
    public List<Auction> getFind(String auctionName) {
        QueryWrapper<Auction> wrapper=new QueryWrapper<>();
        wrapper.like("auctionName",auctionName!=null?auctionName:"").or().like("auctionDesc",auctionName!=null?auctionName:"");
        return auctionMapper.selectList(wrapper);
    }

    @Override
    public List<Auction> mylist(List<Integer> integerList) {
        List<Auction> a=this.auctionMapper.mylist(integerList);
        return a;
    }

    @Override
    public List<Integer> mylistPage(String auctionName) {
        return this.auctionMapper.mylistPage(auctionName);
    }

    @Override
    public Auction updateAll(Integer auctionId) {
        return auctionMapper.updateAll(auctionId);
    }
}
